import { CustomHighLightListCommand, CustomLoadOBJInfosCommand } from "../command/custom.command"
import TourData from "../data/TourData"
import Sdk from "../module/SdkModule"
import { Func } from "./setup"
import { DependencyFetcher } from "./utils"
export default {
  Event: (sdk: Sdk) => {
    sdk.addEnumToInterface({ namespace: "Custom", name: "Event", values: {} })
  },
  highLightList: (sdk: Sdk, allFunc: Func, dependencies: DependencyFetcher<[Promise<TourData>]>) => {
    sdk.addCommandCreator({ namespace: "Custom", name: "highLightList", args: ["data"] }, e => {
      const data = Array.isArray(e.data) ? e.data : [e.data]
      return new CustomHighLightListCommand(data)
    })
    allFunc.addBinding(CustomHighLightListCommand, async data => {
      const [tourData] = await dependencies.getDependencies()
      const { activeReel } = tourData

      activeReel.reel.elements = data
      tourData.enabledTourStops = []
      activeReel.reel.elements.forEach(item => {
        const { sid } = item
        tourData.enabledTourStops.push(sid)
      })
      activeReel.reel.length = data.length
      activeReel.commit()
      tourData.commit()
    })
  },
  loadObjInfos: (sdk: Sdk, allFunc: Func, dependencies) => {
    sdk.addCommandCreator({ namespace: "Custom", name: "loadObjInfos", args: ["infos", "readOnly"] }, e => {
      return new CustomLoadOBJInfosCommand(e)
    })
    allFunc.addBinding(CustomLoadOBJInfosCommand, async data => {
      const [extObjModule] = await dependencies.getDependencies()
      const { infos, readOnly } = data
      await extObjModule.loadObjInfos(Array.isArray(infos) ? infos : [infos], readOnly)
    })
  }
}
